import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../ivy_ezviz_plugin.dart';
import 'EzvizUIKitView.dart';

class FullScreen extends StatefulWidget {
  ///
  Hero hero;

  FullScreen({@required this.hero});

  @override
  _FullScreenState createState() => _FullScreenState();
}

class _FullScreenState extends State<FullScreen> {
  ValueNotifier<bool> flag = ValueNotifier<bool>(true);
  ValueNotifier<bool> isLand = ValueNotifier<bool>(true);

  @override
  void initState() {
    SystemChrome.setPreferredOrientations(// 使设备横屏显示
        [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
      child: Stack(
        children: [
          Container(color: Colors.black, child: widget.hero),
          Positioned.fill(
              child: GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              ///展示
              flag.value = !flag.value;
            },
            child: Container(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  ///上
                  Container(
                    color: Colors.transparent,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Expanded(child: Container()),

                        ///
                        Padding(
                          padding: EdgeInsets.only(left: 20, right: 20,top: MediaQuery.of(context).padding.top+10),
                          child: IconButton(
                              icon: Icon(
                                Icons.clear,
                                color: Colors.white,
                                size: 30,
                              ),
                              onPressed: () {
                                SystemChrome.setPreferredOrientations(// 使设备横屏显示
                                    [
                                  DeviceOrientation.portraitUp,
                                  DeviceOrientation.portraitDown
                                ]);

                                ///退出
                                Navigator.of(context).pop();
                              }),
                        )
                      ],
                    ),
                  ),
                  Expanded(child: Container()),

                  ///下
                  Container(
                    color: Colors.black45,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Expanded(child: Container()),

                        ///
                        ValueListenableBuilder(
                            valueListenable: flag,
                            builder: (_, value, __) {
                              return Visibility(
                                  visible: value,
                                  child: Padding(
                                    padding:
                                        EdgeInsets.only(left: 20, right: 20),
                                    child: ValueListenableBuilder(
                                      valueListenable: isLand,
                                      builder: (_, isLandvalue, __) {
                                        return IconButton(
                                            icon: Icon(
                                              isLandvalue
                                                  ? Icons.screen_lock_portrait
                                                  : Icons.screen_lock_landscape,
                                              color: Colors.white,
                                              size: 30,
                                            ),
                                            onPressed: () {
                                              ///true竖屏
                                              if(isLandvalue){
                                                SystemChrome
                                                    .setPreferredOrientations(// 使设备横屏显示
                                                    [
                                                      DeviceOrientation.landscapeLeft,
                                                      DeviceOrientation.landscapeRight
                                                    ]);
                                              }else{
                                                SystemChrome
                                                    .setPreferredOrientations(// 使设备横屏显示
                                                    [
                                                      DeviceOrientation.portraitUp,
                                                      DeviceOrientation.portraitDown
                                                    ]);
                                              }
                                              isLand.value = !isLand.value;

                                            });
                                      },
                                    ),
                                  ));
                            }),
                      ],
                    ),
                  )
                ],
              ),
            ),
          )),
        ],
      ),
    ));
  }
}
